package Easy.LinkedList;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: white-zhou
 * @date: 2024-09-10 19:19
 **/
public class GetIntersectionNode {
    public static class ListNode {
      int val;
      ListNode next;
      ListNode(int x) {
          val = x;
          next = null;
      }
  }

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) return null;
        List<ListNode> list = new ArrayList<>();
        ListNode cur = headA;
        while (cur != null) {
            list.add(cur);
            cur = cur.next;
        }
        cur = headB;
        while (cur != null) {
            if (list.contains(cur)) {
                return cur;
            }
            cur = cur.next;
        }
        return null;
    }
}
